from flask import Flask, make_response, request
from flask_cors import CORS
import string

# configuration
DEBUG = True

# instantiate the app
app = Flask(__name__)
app.config.from_object(__name__)

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})


# sanity check route
@app.route("/api/login", methods=["POST"])
def test_login():
    return make_response({'ok': True})


@app.route("/api/register", methods=["POST"])
def test_register():
    return make_response({'ok': True})


@app.route("/api/password", methods=["POST"])
def test_password():
    return make_response({'ok': True})


@app.route("/api/appointment", methods=["POST"])
def test_appoint():
    return make_response({'ok': True})


@app.route("/api/changeRequest", methods=["POST"])
def test_change_request():
    return make_response({'ok': True})


@app.route("/api/pay", methods=["POST"])
def test_pay():
    return make_response({'ok': True})


@app.route("/api/admin/power_set", methods=["POST"])
def test_power_set():
    return make_response({'ok': True})


@app.route("/api/admin/stations_list", methods=["GET"])
def test_sations_list():
    res = {
        'num': 2,
        'stations': [
            {'id': '001',
             'type': 'F',
             'is_on': 1,
             'is_serve': 0,
             'serves': 3,
             'time_finish': 78,
             'power_finish': 12,
             'serve_id': '09'
             },
            {
                'id': '002',
                'type': 'F',
                'is_on': 1,
                'is_serve': 0,
                'serves': 3,
                'time_finish': 78,
                'power_finish': 12,
                'serve_id': '09'
            }
        ]
    }
    return make_response(res)


@app.route("/api/admin/charge_queue", methods=["GET"])
def test_queue_list():
    id = request.pragma
    print(id)
    station_id = request.form.get('name')
    res = {
        'id': station_id,
        'num': 2,
        'queue': [
            {
                'queue_id': 5,
                'user_id': 123,
                'capcity': '500',
                'request_power': '400',
                'time_in_queue': '30'
            },
            {
                'queue_id': 5,
                'user_id': 123,
                'capcity': '500',
                'request_power': '500',
                'time_in_queue': '30'
            }
        ]

    }
    return make_response(res)


@app.route("/api/admin/reports_list", methods=["GET"])
def test_reports_list():
    res = {
        'num': 2,
        'stations': [
            {
                'id': '001',
                'date': '20220606',
                'all_serves': 1,
                'all_time': 390,
                'all_power': 8941,
                'all_power_fees': 780,
                'all_serve_fees': 220,
                'all_fees': 1000
            },
            {
                'id': '002',
                'date': '20220606',
                'all_serves': 1,
                'all_time': 3829,
                'all_power': 1293,
                'all_power_fees': 780,
                'all_serve_fees': 220,
                'all_fees': 1000
            }
        ]
    }
    return make_response(res)


@app.route("/api/admin/station_faulure", methods=["POST"])
def test_power_fault():
    return make_response({'ok': True})


@app.route("/api/admin/station_recover", methods=["POST"])
def test_power_recovery():
    return make_response({'ok': True})


@app.route("/api/send_appoint", methods=["POST"])
def test_send_appoint():
    return make_response({'ok': True})


@app.route("/api/change_appoint", methods=["POST"])
def test_change_appoint():
    return make_response({'ok': True})


if __name__ == '__main__':
    app.run()
